<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<style type="text/css">
.photo
{
    margin-left:auto;
    margin-right:auto;
    margin-top:5px;
    width:30px;
    height:30px;
    overflow:hidden;
    background-color:#f8fdff;
    border:4px solid #f3f3f3;
    text-align:center;
    vertical-align:bottom;
    line-height:32px; 
    display:block;
}

.photoTitle
{
    margin-left:auto;
    margin-right:auto;
    display:table;
    padding-top:0px;
    
    *padding-left:15px;
    _padding-left:15px;
}
</style>
<script type="text/javascript" src="<%=path%>/include/FileUpload/fileUpload.js"></script>
<script type="text/javascript">
function delFile(preSavePath){
	savePath = document.getElementById("myphoto").savePath;
    $.ajax({
		type: "POST", url: "<%=path%>/servlet/FileUploadManagerServlet?method=delImage&filePath="+savePath,
		data:$("#form1").serialize(),
		error:function(){alert("与服务器失去联系，请刷新本页面后再重试！");},
		success: function(msg){
			//页面去除img的属性
			$("#myphoto").attr("src","");
			$("#myphoto").attr("savePath","");
		}
	});
 }


//上传组件参数初始化
var setting={
	id:"FileUpload",
	swfPath:"<%=path%>/include/FileUpload/FileUploadForHr.swf",
	serverPath:"<%=path%>/servlet/FileUploadManagerServlet?method=savePhoto",
	imgPath:"<%=path%>/include/FileUpload/uploadPhoto.jpg",
	width:160,
	height:20,
 	fileSize:"20",
	noFileType:"*.exe",
 	checkAndUploadExtend:checkAndUploadExtend,
 	uploadOnProgressExtend:uploadOnProgressExtend,
 	uploadCompleteExtend:uploadCompleteExtend
};


/*上传文件有效性判断*/
function checkAndUploadExtend(id,serverJson){

	//记录前一次上传的图片的url
	prePhotoSavePath = document.getElementById("myphoto").savePath;
    
	//如果你想获取当前上传组件参数的话
	//var parameters=FU.getSettingById[id];
	if(serverJson.checkType=="all"){
		//各种校验通过,如果你想在文件正式上传前做点什么的话，你就在这做吧！
		//alert("serverJson:"+serverJson);
		
		//$("#fileInfo").html(serverJson.fileName);
		//$("#json1").html(FU.jsonToStr(serverJson));
	}else if(serverJson.checkType=="suffix"){
		//文件后缀名有误
		alert("文件后缀名有误1");
	}else if(serverJson.checkType=="noSuffix"){
		//不允许的后缀名出错
		alert("不允许的后缀名有误1");
	}else if(serverJson.checkType=="size"){
		//文件大小有误
		alert("文件大小超过限制,请上传20以内的附件.");
	}
}

/*文件上传进度控制*/
function uploadOnProgressExtend(id,serverJson){
	var percentFormat=Math.floor(serverJson.percent*100);
	//$("#json2").html(FU.jsonToStr(serverJson));
	//$("#perspan").html(percentFormat+"%");
}

/*文件上传成功后，将服务器返回值返回到页面*/
function uploadCompleteExtend(id,serverJson){
	//如果你想在文件上传结束后做点什么的话，你就在这做吧！
	var imageObj = eval("("+serverJson+")");
//	alert("返回文件名："+imageObj.fileName);//返回文件名
//	alert("返回照片相对路径："+imageObj.imgPath);//返回照片相对路径
//	alert("返回压缩后照片的相对路径："+imageObj.smallImgPath);//返回压缩后照片的相对路径
	
	//页面读取照片的url
	var imagurl = '<%=path%>/servlet/FileUploadManagerServlet?method=showImage&imgPath='+imageObj.imgPath;
	$.ajax({
		type: "POST", url: '<%=path%>/album?method=savePhoto&personuuid=<%=personuuid%>&imgpath='+imageObj.imgPath+'&smallimgpath='+imageObj.smallImgPath,
		error:function(){alert("与服务器失去联系，请刷新本页面后再重试！");},
		success: function(msg){}
		});
	//设置img的src属性
	$("#myphoto").attr("src",imagurl);
	$("#myphoto").attr("savePath",imageObj.imgPath);
}

function _changestatus(){
	var obj = document.getElementById("workstatus");
	$.ajax({
		type: "POST", url: '<%=path%>/regist/registservlet?method=changeStatus&personuuid=<%=personuuid%>&workstatus='+obj.value,
		error:function(){alert("无法完成修改状态操作，请稍后再试！");},
		success: function(msg){}
		});
}


function setzhaopianurl(){
	var obj = document.getElementById("zhaopianurl");
	var pobj = document.getElementById("myphoto");
	if(obj.value==""){
		pobj.src="<%=path%>/upload/user/nobody.gif";
	}else{
		pobj.src="<%=path%>/servlet/FileUploadManagerServlet?method=showImage&imgPath="+obj.value;
	}
}
//setzhaopianurl();

</script>
	<table border="0" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC" width="100%">
    <tr>
    	<td colspan="3">
        <script>
			//调用上传组件
			FU.iniFlashPlayer(setting);
        </script>
        </td>
    </tr>
    <tr>
    	<td width="60" height="35">缩略图</td>
        <td width="480">文件名</td>
        <td width="60">操作</td>
    </tr>
    <tr>
    	<td width="60" height="35">
        <div id="carImageDiv" class="photo">
        	<input id="zhaopianurl" type="hidden" value="">
            <img id="myphoto" name="myphoto" savePath="" alt="" width="160" height="160" src="" style="border: 0px;" />
        </div>
        </td>
        <td width="480">文件名</td>
        <td width="60">操作</td>
    </tr>
    </table>